<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>全选 全不选 反选</title>
	<style type="text/css">

	table{width:400px;height:200px;border-collapse:collapse;text-align:center;}


	</style>
</head>
<body>
	<center>
	<table border='1'>
		<caption><h2>学生信息表</h2></caption>
		<tr>
			<td>&nbsp;</td>
			<td>序号</td>
			<td>姓名</td>
			<td>年龄</td>
		</tr>
		<tr>
			<td><input type="checkbox" name='box[]'></td>
			<td>1</td>
			<td>张舫</td>
			<td>18</td>
		</tr>
		<tr>
			<td><input type="checkbox" name='box[]'></td>
			<td>2</td>
			<td>王宝强</td>
			<td>30</td>
		</tr>
		<tr>
			<td><input type="checkbox" name='box[]'></td>
			<td>3</td>
			<td>宋吉吉</td>
			<td>30</td>
		</tr>
		<tr>
			<td colspan='4'>
				<button id='sel'>全选</button>
				<button id='nosel'>全不选</button>
				<button id='fsel'>反选</button>
			</td>
		</tr>

	</table>
	</center>

	<script type="text/javascript">
	//获取元素
	var sel = document.getElementById('sel');
	var nosel = document.getElementById('nosel');
	var fsel = document.getElementById('fsel');
	var boxs = document.getElementsByName('box[]');

	sel.onlick = functon()
	{
		for(var i= 0;i<boxs.length; i++)
		{
			boxs[i].checked = true;
		}
	}



//	sel.onclick = function()
//	{
//
//
//		for (var i = 0; i < boxs.length; i++) {
//
//			boxs[i].checked = true;
//		};
//	}
//
//	nosel.onclick = function()
//	{
//		for (var i = 0; i < boxs.length; i++) {
//
//			boxs[i].checked = false;
//		};
//	}
//
//	fsel.onclick = function()
//	{
//		for (var i = 0; i < boxs.length; i++) {
//
//			boxs[i].checked = ! boxs[i].checked;
////			if(boxs[i].checked == true) {
////
////				boxs[i].checked = false;
////			} else {
////				boxs[i].checked = true;
////			}
//		};
//	}



	</script>
</body>
</html>